package config

import (
	"gitee.com/dreamwood/ez"
	"os"
)

type CoreConfig struct {
	ServerRoot string `yaml:"server-root"`
	ServerHost string `yaml:"server-host"`
	ServerPort int    `yaml:"server-port"`
	NsqSubAddr string `yaml:"nsq-sub-addr"`
	NsqPubAddr string `yaml:"nsq-pub-addr"`
	Vi         string `yaml:"vi"`
	IsDev      bool   `yaml:"is-dev"`
}

var coreConfig *CoreConfig

func init() {
	CreateCoreConfig()
}

func CreateCoreConfig() {
	ez.CreateConfigFromYml("./app.yaml", "ez", &coreConfig)
}

func GetCore() *CoreConfig {
	if coreConfig == nil {
		CreateApiConfig()
	}
	return coreConfig
}

func (c *CoreConfig) GetRoot() string {
	if c.IsDev {
		return c.ServerRoot
	} else {
		if c.ServerRoot == "" {
			root, _ := os.Getwd()
			return root
		} else {
			return c.ServerRoot
		}
	}
}
